home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
windows
/
prinfon
/
ajcprt.arj
/
AJCPRNTW.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-01-16
|
6KB
|
200 lines
{************************************************}
{ }
{ AJC Printer Unit for Windows }
{ }
{ Printer control constants/functions }
{ }
{ Author: Andrew J. Cook }
{ Omaha, NE }
{ CompuServe ID: 71331,501 }
{ }
{ Written: January 1994 }
{ }
{ Copyright: None! I hereby commit this unit }
{ to the public domain. }
{ }
{************************************************}
unit AJCPrntW;
{$F+,O+,S-}
interface
uses WinTypes, WinProcs, OPrinter;
type
PAJCPrinter = ^TAJCPrinter;
TAJCPrinter = object(TPrinter)
function SetPageOrientation(Orientation: Integer): Integer; virtual;
end;
const
pm_Size = 1;
pm_Print = 2;
type
PAJCPrintOut = ^TAJCPrintOut;
TAJCPrintOut = object(TPrintOut)
VUnitsPerInch: Integer;
HUnitsPerInch: Integer;
LMarginUnits: Integer;
TMarginUnits: Integer;
OriginalAlignmentOptions: Word;
constructor Init(ATitle: PChar);
destructor Done; virtual;
procedure SetPrintParams(ADC: HDC; ASize: TPoint); virtual;
function VLogPos(Pos: Integer): Integer; virtual;
function HLogPos(Pos: Integer): Integer; virtual;
function VInches(Inches: Real): Integer; virtual;
function HInches(Inches: Real): Integer; virtual;
function Points(APoints: Integer): Integer; virtual;
function PrintHeader(Mode, Page: Word): Integer; virtual;
function PrintFooter(Mode, Page: Word): Integer; virtual;
procedure JustifyLeft;
procedure JustifyCenter;
procedure JustifyRight;
end;
implementation
function TAJCPrinter.SetPageOrientation(Orientation: Integer): Integer;
var
DevMode: PDevMode;
Result: Integer;
begin
SetPageOrientation := -1;
if (Orientation <> dmOrient_Portrait) and
(Orientation <> dmOrient_Landscape) then
exit;
if @ExtDeviceMode = nil then exit;
if DevSettings^.dmFields or dm_Orientation = 0 then exit;
if DevSettings^.dmOrientation = Orientation then
begin
SetPageOrientation := 1;
exit;
end;
GetMem(DevMode, DevSettingSize);
Move(DevSettings^, DevMode^, DevSettingSize);
DevMode^.dmOrientation := Orientation;
Result := ExtDeviceMode(0, DeviceModule, DevSettings^, Device, Port,
DevMode^, nil, dm_In_Buffer or dm_Out_Buffer);
FreeMem(DevMode, DevSettingSize);
if Result = IDOK then
SetPageOrientation := 0;
end;
constructor TAJCPrintOut.Init(ATitle: PChar);
begin
inherited Init(ATitle);
OriginalAlignmentOptions := 0;
end;
destructor TAJCPrintOut.Done;
begin
if OriginalAlignmentOptions <> 0 then
SetTextAlign(DC, OriginalAlignmentOptions);
inherited Done;
end;
procedure TAJCPrintOut.SetPrintParams(ADC: HDC; ASize: TPoint);
begin
inherited SetPrintParams(ADC, ASize);
OriginalAlignmentOptions := GetTextAlign(DC);
VUnitsPerInch := GetDeviceCaps(DC, LogPixelsY);
HUnitsPerInch := GetDeviceCaps(DC, LogPixelsX);
if (1.0*Size.Y)/VUnitsPerInch > (1.0*Size.X)/HUnitsPerInch then
begin
TMarginUnits := (VInches(11) - Size.Y) div 2;
LMarginUnits := (HInches(8.5) - Size.X) div 2;
end
else
begin
TMarginUnits := (VInches(8.5) - Size.Y) div 2;
LMarginUnits := (HInches(11) - Size.X) div 2;
end;
end;
function TAJCPrintOut.VLogPos(Pos: Integer): Integer;
begin
if Pos < 0 then
VLogPos := Size.Y + Pos + TMarginUnits
else
VLogPos := Pos - TMarginUnits;
end;
function TAJCPrintOut.HLogPos(Pos: Integer): Integer;
begin
if Pos < 0 then
HLogPos := Size.X + Pos + LMarginUnits
else
HLogPos := Pos - LMarginUnits;
end;
function TAJCPrintOut.VInches(Inches: Real): Integer;
begin
VInches := round(Inches * VUnitsPerInch);
end;
function TAJCPrintOut.HInches(Inches: Real): Integer;
begin
HInches := round(Inches * HUnitsPerInch);
end;
function TAJCPrintOut.Points(APoints: Integer): Integer;
begin
Points := APoints * (VUnitsPerInch) div 72;
end;
function TAJCPrintOut.PrintHeader(Mode, Page: Word): Integer;
begin
PrintHeader := 0;
end;
function TAJCPrintOut.PrintFooter(Mode, Page: Word): Integer;
begin
PrintFooter := 0;
end;
procedure TAJCPrintOut.JustifyLeft;
var
AlignmentOptions: Word;
begin
AlignmentOptions := GetTextAlign(DC);
AlignmentOptions := AlignmentOptions and not (ta_left or ta_center or ta_right);
AlignmentOptions := AlignmentOptions or ta_left;
SetTextAlign(DC, AlignmentOptions);
end;
procedure TAJCPrintOut.JustifyCenter;
var
AlignmentOptions: Word;
begin
AlignmentOptions := GetTextAlign(DC);
AlignmentOptions := AlignmentOptions and not (ta_left or ta_center or ta_right);
AlignmentOptions := AlignmentOptions or ta_center;
SetTextAlign(DC, AlignmentOptions);
end;
procedure TAJCPrintOut.JustifyRight;
var
AlignmentOptions: Word;
begin
AlignmentOptions := GetTextAlign(DC);
AlignmentOptions := AlignmentOptions and not (ta_left or ta_center or ta_right);
AlignmentOptions := AlignmentOptions or ta_right;
SetTextAlign(DC, AlignmentOptions);
end;
begin
end.